﻿using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace HtmlParserLib.Parsers
{
    /// <summary>
    /// 中华人民共和国财政部
    /// </summary>
    class MofGovCn : CommonHtmlParser
    {
        protected override IEnumerable<HtmlNode> SelectLinkNodes(HtmlDocument doc)
        {
            var linkedPages = doc.DocumentNode.SelectNodes("//table[@id='id_bl']//a[@href]");
            var result = linkedPages.Reverse();
            return result;
        }

        protected override string GetOtherInfo(HtmlNode link)
        {
            var title = link.ParentNode.Attributes["title"].Value;
            var p = @"\d{4}-\d{1,2}-\d{1,2}";
            var m = Regex.Match(title, p);
            if (m.Success)
            {
                return m.Value;
            }
            else
            {
                return title;
            }
        }
    }
}
